import java.io.*;
import java.util.Scanner;

/*
 ID: ning yusui
 LANG: JAVA
 TASK: rect1
 */

public class rect1 {
    Scanner in;
    PrintWriter out;
    private Rect[] data;
    private int[] colorCnt = new int[1000 + 1];

    public rect1() throws IOException {
        in = new Scanner(new File(this.getClass().getName() + ".in"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(this.getClass().getName() +
                ".out")));
    }

    void cut(Rect back, int start) {
        if(back==null ) return;
        int index = findMayCross(back, start);
        if (index != -1) {
            Rect fore = data[index];
            if (fore.contains(back)) {
                return;
            } else {
                int lx = Math.max(fore.lx, back.lx);
                int ly = Math.max(fore.ly, back.ly);
                int ux = Math.min(fore.ux, back.ux);
                int uy = Math.min(fore.uy, back.uy);
                Rect cutPart;
                cutPart = Rect.create(ux, back.ly, back.ux, back.uy, back.color);
                if (cutPart != null) {
                    cut(cutPart, index + 1);
                }
                cutPart = Rect.create(back.lx, back.ly, lx, back.uy, back.color);
                if (cutPart != null) {
                    cut(cutPart, index + 1);
                }
                cutPart = Rect.create(lx, uy, ux, back.uy, back.color);
                if (cutPart != null) {
                    cut(cutPart, index + 1);
                }
                cutPart = Rect.create(lx, back.ly, ux, ly, back.color);
                if (cutPart != null) {
                    cut(cutPart, index + 1);
                }
            }
        } else {
            colorCnt[back.color] += back.area();
        }
    }

    private int findMayCross(Rect back, int start) {
        for (int i = start; i < data.length; i++) {
            if (data[i] != null && !data[i].notCross(back)) {
                return i;
            }
        }
        return -1;
    }

    private void work() {
        int A = in.nextInt();
        int B = in.nextInt();
        int n = in.nextInt();
        data = new Rect[n];
        for (int i = 0; i < data.length; i++) {
            data[i] = Rect.create(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
        }
        opt(data);
        for (int i = data.length-1; i >= 0; i--) {
            if (data[i] != null) {
                cut(data[i], i + 1);
            }
        }
        colorCnt[1]=A*B;
        for(int i=2; i<colorCnt.length; i++){
            colorCnt[1] -= colorCnt[i];
        }
        for (int i = 1; i < colorCnt.length; i++) {
            if (colorCnt[i] > 0) {
                long start = System.currentTimeMillis();
                out.println(i + " " + colorCnt[i]);
                System.out.println(i +":"+ (System.currentTimeMillis() - start) + "ms");
            }
        }
        out.flush();
        out.close();
    }

    private void opt(Rect[] data) {
        tagOut:
        for (int i = 0; i < data.length; i++) {
            for (int j = i + 1; j < data.length; j++) {
                if (data[j].contains(data[i])) {
                    data[i] = null;
                    continue tagOut;
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        new rect1().work();
        System.out.println(System.currentTimeMillis() - start + "ms");
    }

    static class Rect {
        int lx;
        int ly;
        int ux;
        int uy;
        int color;

        static Rect create(int lx, int ly, int ux, int uy, int color) {
            if (lx >= ux || ly >= uy) {
                return null;
            }
            return new Rect(lx, ly, ux, uy, color);
        }

        private Rect(int lx, int ly, int ux, int uy, int color) {
            this.lx = lx;
            this.ly = ly;
            this.ux = ux;
            this.uy = uy;
            this.color = color;
        }

        boolean notCross(Rect r) {
            return r.lx >= this.ux || r.ux <= this.lx || r.ly >= this.uy || r.uy <= this.ly;
        }

        boolean contains(Rect r) {
            return r.lx >= this.lx && r.ux <= this.ux && r.ly >= this.ly && r.uy <= this.uy;
        }

        int area() {
            return (ux - lx) * (uy - ly);
        }
    }
}
